Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs found in MAUI repo #6361

Merged
merged 1 commit into from
Dec 20, 2022
Merged

Fix bugs found in MAUI repo #6361

merged 1 commit into from
Dec 20, 2022

Conversation

buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Dec 16, 2022

Two bugs found while investigating #6158 that fixed with this PR

  1. When a child API narrows down parent support version the guarding version was compared with parent version only when it should be compared with child version
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("tvos")]
[SupportedOSPlatform("maccatalyst")]
class Program
{
    [SupportedOSPlatform("tvos10.2")]
    [SupportedOSPlatform("ios10.3")]
    [SupportedOSPlatform("maccatalyst10.3")]
    public static int P1 => 1;
}

class Test
{
    [SupportedOSPlatform("ios10.0")]
    public void M1()
    {
        var rate = (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsMacCatalystVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10, 3))
		    ? Program.P1 // was warning here even if it was guarded
                    : 0; 
    }
}
  1. When a called API has SupportedOSPlatform and ObsoletedOSPlatform attributes both and if the callsite attribute suppresses the Supported version the analyzer should warn only for the Obsoleted version. It was still warning for the Supported attribute even if it was empty / suppressed.
class Program
{
    [ObsoletedOSPlatform("ios7.0", "Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.")]
    [ObsoletedOSPlatform("maccatalyst7.0", "Use 'NSString.GetBoundingRect (CGSize, NSStringDrawingOptions, UIStringAttributes, NSStringDrawingContext)' instead.")] // maccatalyst covered by ios, this attribute redundant
    [SupportedOSPlatform("ios")]
    [SupportedOSPlatform("maccatalyst")] // maccatalyst covered by ios, this attribute redundant
    public static void M3() { }
    
    [SupportedOSPlatform("ios")]
    public static void M1()
    {
         M3(); // it was reporting 2 diagnostics here, CA1416 and CA1422 when only CA1422 was expected
    }
}

Fixes #6158

@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #6361 (544db0c) into main (1eb2caf) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6361    +/-   ##
========================================
  Coverage   96.08%   96.08%            
========================================
  Files        1367     1360     -7     
  Lines      315352   315583   +231     
  Branches    10187    10189     +2     
========================================
+ Hits       302991   303234   +243     
+ Misses       9930     9916    -14     
- Partials     2431     2433     +2     

@buyaa-n buyaa-n merged commit f10e7f2 into dotnet:main Dec 20, 2022
@buyaa-n buyaa-n deleted the fix-bug branch December 20, 2022 21:30
@github-actions github-actions bot added this to the vNext milestone Dec 20, 2022
buyaa-n added a commit to buyaa-n/roslyn-analyzers that referenced this pull request Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET MAUI seeing lots of new CA1416 warnings
2 participants